home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / ASL_DHRY / DHRY_1.C next >
Text File  |  1991-12-11  |  12KB  |  426 lines

  1. /*
  2.  ****************************************************************************
  3.  *
  4.  *                   "DHRYSTONE" Benchmark Program
  5.  *                   -----------------------------
  6.  *                                                                            
  7.  *  Version:    C, Version 2.1
  8.  *                                                                            
  9.  *  File:       dhry_1.c (part 2 of 3)
  10.  *
  11.  *  Date:       May 25, 1988
  12.  *
  13.  *  Author:     Reinhold P. Weicker
  14.  *
  15.  ****************************************************************************
  16.  */
  17.  
  18. #include "dhry.h"
  19.  
  20. /* Global Variables: */
  21.  
  22. Rec_Pointer     Ptr_Glob,
  23.                 Next_Ptr_Glob;
  24. int             Int_Glob;
  25. Boolean         Bool_Glob;
  26. char            Ch_1_Glob,
  27.                 Ch_2_Glob;
  28. int             Arr_1_Glob [50];
  29. int             Arr_2_Glob [50] [50];
  30.  
  31. #if !MAC /* H.Y */
  32. extern char     *malloc ();
  33.  
  34. Enumeration     Func_1 ();
  35.   /* forward declaration necessary since Enumeration may not simply be int */
  36. #endif
  37.  
  38. #ifndef REG
  39.         Boolean Reg = false;
  40. #define REG
  41.         /* REG becomes defined as empty */
  42.         /* i.e. no register variables   */
  43. #else
  44.         Boolean Reg = true;
  45. #endif
  46.  
  47. /* variables for time measurement: */
  48.  
  49. #ifdef TIMES
  50. struct tms      time_info;
  51. extern  int     times ();
  52.                 /* see library function "times" */
  53. #define Too_Small_Time 120
  54.                 /* Measurements should last at least about 2 seconds */
  55. #endif
  56. #ifdef TIME
  57. extern long     time();
  58.                 /* see library function "time"  */
  59. #define Too_Small_Time 2
  60.                 /* Measurements should last at least 2 seconds */
  61. #endif
  62.  
  63. #if MAC /* H.Y */
  64. #define Too_Small_Time 60
  65.                 /* Measurements should last at least 1 seconds */
  66. #endif
  67.  
  68. long            Begin_Time,
  69.                 End_Time,
  70.                 User_Time;
  71. float           Microseconds,
  72.                 Dhrystones_Per_Second;
  73.  
  74. /* end of variables for time measurement */
  75.  
  76.  
  77. main ()
  78. /*****/
  79.  
  80.   /* main program, corresponds to procedures        */
  81.   /* Main and Proc_0 in the Ada version             */
  82. {
  83.         One_Fifty       Int_1_Loc;
  84.   REG   One_Fifty       Int_2_Loc;
  85.         One_Fifty       Int_3_Loc;
  86.   REG   char            Ch_Index;
  87.         Enumeration     Enum_Loc;
  88.         Str_30          Str_1_Loc;
  89.         Str_30          Str_2_Loc;
  90.   REG   int             Run_Index;
  91.   REG   int             Number_Of_Runs;
  92.  
  93.   /* Initializations */
  94.  
  95.   Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  96.   Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  97.  
  98.   Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
  99.   Ptr_Glob->Discr                       = Ident_1;
  100.   Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
  101.   Ptr_Glob->variant.var_1.Int_Comp      = 40;
  102.   strcpy (Ptr_Glob->variant.var_1.Str_Comp, 
  103.           "DHRYSTONE PROGRAM, SOME STRING");
  104.   strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
  105.  
  106.   Arr_2_Glob [8][7] = 10;
  107.         /* Was missing in published program. Without this statement,    */
  108.         /* Arr_2_Glob [8][7] would have an undefined value.             */
  109.         /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
  110.         /* overflow may occur for this array element.                   */
  111.  
  112.   printf ("\n");
  113.   printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
  114.   printf ("\n");
  115.  
  116. #if MAC /* H.Y */
  117. #if THINK_C
  118.   printf("Macintosh Dhrystone 2.1 12/11/91 (THINK C 5.0.1) by Hiroo Yamada\n\n");
  119.  
  120. #if __option(int_4)
  121.   printf("32bit int version\n\n");
  122. #else
  123.   printf("16bit int version\n\n");
  124. #endif
  125.  
  126. #else
  127.   printf("Macintosh Dhrystone 2.1 12/11/91 (MPW C 3.2) by Hiroo Yamada\n\n");
  128. #endif
  129. #endif
  130.  
  131.   if (Reg)
  132.   {
  133.     printf ("Program compiled with 'register' attribute\n");
  134.     printf ("\n");
  135.   }
  136.   else
  137.   {
  138.     printf ("Program compiled without 'register' attribute\n");
  139.     printf ("\n");
  140.   }
  141.  
  142. #if MAC /* H.Y */
  143.   Number_Of_Runs = 30000;    /* enough loop counts for macintosh    */
  144. #else
  145.   printf ("Please give the number of runs through the benchmark: ");
  146.   {
  147.     int n;
  148.     scanf ("%d", &n);
  149.     Number_Of_Runs = n;
  150.   }
  151.   printf ("\n");
  152. #endif
  153.  
  154.   printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
  155.  
  156. #if MAC /* H.Y */
  157.   fflush(stdout);
  158. #endif
  159.  
  160.   /***************/
  161.   /* Start timer */
  162.   /***************/
  163.  
  164. #ifdef TIMES
  165.   times (&time_info);
  166.   Begin_Time = (long) time_info.tms_utime;
  167. #endif
  168. #ifdef TIME
  169.   Begin_Time = time ( (long *) 0);
  170. #endif
  171.  
  172. #if MAC /* H.Y */
  173.   Begin_Time=TickCount();
  174. #endif
  175.  
  176.   for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
  177.   {
  178.  
  179.     Proc_5();
  180.     Proc_4();
  181.       /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  182.     Int_1_Loc = 2;
  183.     Int_2_Loc = 3;
  184.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  185.     Enum_Loc = Ident_2;
  186.     Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
  187.       /* Bool_Glob == 1 */
  188.     while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
  189.     {
  190.       Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  191.         /* Int_3_Loc == 7 */
  192.       Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  193.         /* Int_3_Loc == 7 */
  194.       Int_1_Loc += 1;
  195.     } /* while */
  196.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  197.     Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  198.       /* Int_Glob == 5 */
  199.     Proc_1 (Ptr_Glob);
  200.     for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  201.                              /* loop body executed twice */
  202.     {
  203.       if (Enum_Loc == Func_1 (Ch_Index, 'C'))
  204.           /* then, not executed */
  205.         {
  206.         Proc_6 (Ident_1, &Enum_Loc);
  207.         strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  208.         Int_2_Loc = Run_Index;
  209.         Int_Glob = Run_Index;
  210.         }
  211.     }
  212.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  213.     Int_2_Loc = Int_2_Loc * Int_1_Loc;
  214.     Int_1_Loc = Int_2_Loc / Int_3_Loc;
  215.     Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  216.       /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  217.     Proc_2 (&Int_1_Loc);
  218.       /* Int_1_Loc == 5 */
  219.  
  220.   } /* loop "for Run_Index" */
  221.  
  222.   /**************/
  223.   /* Stop timer */
  224.   /**************/
  225.   
  226. #ifdef TIMES
  227.   times (&time_info);
  228.   End_Time = (long) time_info.tms_utime;
  229. #endif
  230. #ifdef TIME
  231.   End_Time = time ( (long *) 0);
  232. #endif
  233.  
  234. #if MAC /* H.Y */
  235.   End_Time=TickCount();
  236. #endif
  237.  
  238.   printf ("Execution ends\n");
  239.   printf ("\n");
  240.   printf ("Final values of the variables used in the benchmark:\n");
  241.   printf ("\n");
  242.   printf ("Int_Glob:            %d\n", Int_Glob);
  243.   printf ("        should be:   %d\n", 5);
  244.   printf ("Bool_Glob:           %d\n", Bool_Glob);
  245.   printf ("        should be:   %d\n", 1);
  246.   printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
  247.   printf ("        should be:   %c\n", 'A');
  248.   printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
  249.   printf ("        should be:   %c\n", 'B');
  250.   printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
  251.   printf ("        should be:   %d\n", 7);
  252.   printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
  253.   printf ("        should be:   Number_Of_Runs + 10\n");
  254.   printf ("Ptr_Glob->\n");
  255.   printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
  256.   printf ("        should be:   (implementation-dependent)\n");
  257.   printf ("  Discr:             %d\n", Ptr_Glob->Discr);
  258.   printf ("        should be:   %d\n", 0);
  259.   printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
  260.   printf ("        should be:   %d\n", 2);
  261.   printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
  262.   printf ("        should be:   %d\n", 17);
  263.   printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
  264.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  265.   printf ("Next_Ptr_Glob->\n");
  266.   printf ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
  267.   printf ("        should be:   (implementation-dependent), same as above\n");
  268.   printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
  269.   printf ("        should be:   %d\n", 0);
  270.   printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
  271.   printf ("        should be:   %d\n", 1);
  272.   printf ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
  273.   printf ("        should be:   %d\n", 18);
  274.   printf ("  Str_Comp:          %s\n",
  275.                                 Next_Ptr_Glob->variant.var_1.Str_Comp);
  276.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  277.   printf ("Int_1_Loc:           %d\n", Int_1_Loc);
  278.   printf ("        should be:   %d\n", 5);
  279.   printf ("Int_2_Loc:           %d\n", Int_2_Loc);
  280.   printf ("        should be:   %d\n", 13);
  281.   printf ("Int_3_Loc:           %d\n", Int_3_Loc);
  282.   printf ("        should be:   %d\n", 7);
  283.   printf ("Enum_Loc:            %d\n", Enum_Loc);
  284.   printf ("        should be:   %d\n", 1);
  285.   printf ("Str_1_Loc:           %s\n", Str_1_Loc);
  286.   printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
  287.   printf ("Str_2_Loc:           %s\n", Str_2_Loc);
  288.   printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
  289.   printf ("\n");
  290.  
  291.   User_Time = End_Time - Begin_Time;
  292.  
  293.   if (User_Time < Too_Small_Time)
  294.   {
  295.     printf ("Measured time too small to obtain meaningful results\n");
  296.     printf ("Please increase number of runs\n");
  297.     printf ("\n");
  298.   }
  299.   else
  300.   {
  301. #ifdef TIME
  302.     Microseconds = (float) User_Time * Mic_secs_Per_Second 
  303.                         / (float) Number_Of_Runs;
  304.     Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
  305. #else
  306.     Microseconds = (float) User_Time * Mic_secs_Per_Second 
  307.                         / ((float) HZ * ((float) Number_Of_Runs));
  308.     Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
  309.                         / (float) User_Time;
  310. #endif
  311.     printf ("Microseconds for one run through Dhrystone: ");
  312.     printf ("%6.1f \n", Microseconds);
  313.     printf ("Dhrystones per Second:                      ");
  314.     printf ("%6.1f \n", Dhrystones_Per_Second);
  315.     printf ("\n");
  316.   }
  317. }
  318.  
  319.  
  320. Proc_1 (Ptr_Val_Par)
  321. /******************/
  322.  
  323. REG Rec_Pointer Ptr_Val_Par;
  324.     /* executed once */
  325. {
  326.   REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;  
  327.                                         /* == Ptr_Glob_Next */
  328.   /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
  329.   /* corresponds to "rename" in Ada, "with" in Pascal           */
  330.   
  331.   structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob); 
  332.   Ptr_Val_Par->variant.var_1.Int_Comp = 5;
  333.   Next_Record->variant.var_1.Int_Comp 
  334.         = Ptr_Val_Par->variant.var_1.Int_Comp;
  335.   Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
  336.   Proc_3 (&Next_Record->Ptr_Comp);
  337.     /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp 
  338.                         == Ptr_Glob->Ptr_Comp */
  339.   if (Next_Record->Discr == Ident_1)
  340.     /* then, executed */
  341.   {
  342.     Next_Record->variant.var_1.Int_Comp = 6;
  343.     Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, 
  344.            &Next_Record->variant.var_1.Enum_Comp);
  345.     Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
  346.     Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, 
  347.            &Next_Record->variant.var_1.Int_Comp);
  348.   }
  349.   else /* not executed */
  350.     structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
  351. } /* Proc_1 */
  352.  
  353.  
  354. Proc_2 (Int_Par_Ref)
  355. /******************/
  356.     /* executed once */
  357.     /* *Int_Par_Ref == 1, becomes 4 */
  358.  
  359. One_Fifty   *Int_Par_Ref;
  360. {
  361.   One_Fifty  Int_Loc;  
  362.   Enumeration   Enum_Loc;
  363.  
  364.   Int_Loc = *Int_Par_Ref + 10;
  365.   do /* executed once */
  366.     if (Ch_1_Glob == 'A')
  367.       /* then, executed */
  368.     {
  369.       Int_Loc -= 1;
  370.       *Int_Par_Ref = Int_Loc - Int_Glob;
  371.       Enum_Loc = Ident_1;
  372.     } /* if */
  373.   while (Enum_Loc != Ident_1); /* true */
  374. } /* Proc_2 */
  375.  
  376.  
  377. Proc_3 (Ptr_Ref_Par)
  378. /******************/
  379.     /* executed once */
  380.     /* Ptr_Ref_Par becomes Ptr_Glob */
  381.  
  382. Rec_Pointer *Ptr_Ref_Par;
  383.  
  384. {
  385.   if (Ptr_Glob != Null)
  386.     /* then, executed */
  387.     *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
  388.   Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
  389. } /* Proc_3 */
  390.  
  391.  
  392. Proc_4 () /* without parameters */
  393. /*******/
  394.     /* executed once */
  395. {
  396.   Boolean Bool_Loc;
  397.  
  398.   Bool_Loc = Ch_1_Glob == 'A';
  399.   Bool_Glob = Bool_Loc | Bool_Glob;
  400.   Ch_2_Glob = 'B';
  401. } /* Proc_4 */
  402.  
  403.  
  404. Proc_5 () /* without parameters */
  405. /*******/
  406.     /* executed once */
  407. {
  408.   Ch_1_Glob = 'A';
  409.   Bool_Glob = false;
  410. } /* Proc_5 */
  411.  
  412.  
  413.         /* Procedure for the assignment of structures,          */
  414.         /* if the C compiler doesn't support this feature       */
  415. #ifdef  NOSTRUCTASSIGN
  416. memcpy (d, s, l)
  417. register char   *d;
  418. register char   *s;
  419. register int    l;
  420. {
  421.         while (l--) *d++ = *s++;
  422. }
  423. #endif
  424.  
  425.  
  426.